<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./../css/Public.css">
    <link rel="stylesheet" href="./../css/Reset.css">
    <style>
        #search {
            background-color: #fff;
            border-bottom: 1px solid #b0b0b0;
            width: 100%;
            position: relative;
        }

        #search .searchbox {
            padding: 10px;
        }

        #search .searchbox>input {
            height: 30px;
            width: 90%;
            padding-left: 5%;
            border-radius: 15px;
            background-color: #f1f1f1;
            border: none;
            font-size: 16px;
        }

        #search .button>button {
            width: 63px;
            height: 30px;
            background: #1d6dff;
            border-radius: 15px;
            position: absolute;
            right: 10px;
            top: 10px;
            border: none;
        }

        #search .button>button::before {
            content: '搜索';
            height: 30px;
            line-height: 30px;
            font-size: 16px;
            border: none;
            color: #fff;
        }

        .ulbox {
            display: none;
        }

        .ulbox li {
            list-style: none;
        }

        .ulbox li h4 {
            font: 300 16px/30px "";
            border: 1px solid #ccc;
            background: #f5f5f5;
        }

        .ulbox li div {
            background: #fff;
            overflow: hidden;
            margin-bottom: 3px;
            margin-right: 15px;
            margin-left: 15px;
            margin-right: auto;
            margin-left: auto;
        }

        .ulbox li div a {
            border: 1px solid #ccc;
            text-align: center;
            font: 400 12px/30px "";
            height: 40px;
            line-height: 40px;
            width: 25%;
            float: left;
        }
    </style>
</head>

<body>
    <!--头部-->
    <header id="header">
        <div class="fl logo">
            <a href="./../index.html.html">
                <img src="./../assets/images/logo.png" alt="">
            </a>
        </div>
        <div class="app fr">
            <a href="">
                <img src="./../assets/images/app.png" alt="">
            </a>
        </div>
    </header>
    <!--搜索-->
    <section id="search">
        <div class="searchbox">
            <input type="text" name="" placeholder="请输入你想比价的产品">
        </div>
        <div class="button">
            <button></button>
        </div>
    </section>
    <!-- 内容 -->
    <main>
        <div id="box">
            <ul class="ulbox">
                <!-- <li>
                    <h4>大家电</h4>
                    <div>
                        <a href="">电视</a>
                        <a href="">空调</a>
                        <a href="">影院</a>
                        <a href="">冰箱</a>
                        <a href="">洗衣机</a>
                        <a href="">热水器</a>
                        <a href="">消毒柜</a>
                    </div>
                </li> -->
            </ul>
        </div>
    </main>


    <!--底部-->
    <section id="footer">
        <div class="more">
            <a href="">
                更多优惠信息>>
            </a>
        </div>
        <div class="chart clearfix">
            <span class="chart_in fl">品牌排行</span>
            <span class="more fr">
                <img src="./../assets/images/more.png" alt="">
            </span>
        </div>
        <div class="login">
            <div class="container">
                <div class="row">
                    <a href="">
                        <div class="col-xs-3">登入</div>
                    </a>
                    <a href="">
                        <div class="col-xs-4">注册</div>
                    </a>
                    <a href="">
                        <div class="col-xs-5">返回顶部</div>
                    </a>
                    <span></span>
                </div>
            </div>
            <div class="content_b">
                <p>
                    <a href="#">
                        手机APP下载
                    </a>
                    <a href="#">
                        万锋智慧商城手机版
                    </a>
                    -- 掌上比价平台
                </p>
                <p>
                    chst.vip:8081/crm </p>
            </div>
        </div>


        <script src='https://code.jquery.com/jquery-3.6.0.min.js'></script>
        <script>
            let oul = document.querySelector(".ulbox");
            let titleArr = [];
            let contentArr = [];

            const xhr1 = new XMLHttpRequest();
            xhr1.open("get", "http://chst.vip:1234/api/getcategorytitle", false);
            xhr1.onreadystatechange = function () {
                if (xhr1.readyState === 4) {
                    if (xhr1.status === 200) {
                        let res1 = JSON.parse(xhr1.response);
                        let ele = "";
                        res1.result.forEach(item => {
                            titleArr.push(item.titleId);
                            ele += `<li>
                                    <h4>${item.title}</h4>
                                    <div class="box-li"></div>
                                </li>`
                        });
                        oul.innerHTML = ele;
                    }
                }
            }
            xhr1.send(null)

            titleArr.forEach(value => {
                const xhr2 = new XMLHttpRequest();
                xhr2.open("get", "http://chst.vip:1234/api/getcategory?titleid=" + value, false);
                xhr2.onreadystatechange = function () {
                    if (xhr2.readyState === 4) {
                        if (xhr2.status === 200) {
                            let res2 = JSON.parse(xhr2.response);
                            // console.log(res2);
                            let divContent = ""
                            res2.result.forEach(item => {
                                divContent +=
                                    `<a href="" class="abox">${item.category}</a>`
                            });
                            contentArr.push(divContent);
                            divContent = ""
                        }
                    }
                }
                xhr2.send(null)
            })

            let aDiv = document.querySelectorAll(".ulbox li div")
            aDiv.forEach((item, index) => {
                // console.log(item)
                // console.log(contentArr[index])
                item.innerHTML = contentArr[index];
            });

            $(".ulbox").find("div").slideUp(0, function () {
                $(".ulbox").css("display", "block");

            });

            $(".ulbox li").click(function () {
                $(this).find("div").slideDown().parent().siblings().find("div").slideUp();
            });

            
        </script>
</body>

</html>